﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using PowerCreator.LMS.Web.Question;
using PowerCreator.LMS.Question.Entiry;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Common.Utils;
public partial class sysadmin_QuestionManager_AddQuestionResource : PowerCreator.LMS.Web.Base.BasePage
{
    //ManagerQuestionResourceInfo objManagerQuestionResourceInfo = new ManagerQuestionResourceInfo();
    ManagerQuestion objQuestion = new ManagerQuestion();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["UserID"] = 10000;// Session["UserID"].ToString();
            InitPage();
        }
    }
    protected override void InitPage()
    {
        base.InitPage();

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {


        try
        {
            HttpPostedFile objPostFile = File1.PostedFile;
            if (objPostFile.FileName == "")
            {
                Script.Alert(this, "msg", "请选择文件");
                return;
            }


            FileInfo objFileInfo = new FileInfo(objPostFile.FileName);
            string guid = Guid.NewGuid().ToString();
            string newFileName = guid + objFileInfo.Extension;

            string path = Server.MapPath(WebUtils.WebRoot + "/QeustionResource/" + newFileName);
            objPostFile.SaveAs(path);
            VOQuestionResource objQuestionResourceInfo = new VOQuestionResource();
            if (txtQuestionTypeName.Text == "")
            {
                objQuestionResourceInfo.QuestionResFileName = objFileInfo.Name;
            }
            else
            {
                objQuestionResourceInfo.QuestionResFileName = txtQuestionTypeName.Text;
            }
            objQuestionResourceInfo.QuestionResContent = txt_Content.Text;
            objQuestionResourceInfo.QuestionResGuID = guid;
            objQuestionResourceInfo.QuestionResFileType = int.Parse(ddlSystemType.SelectedValue);
            objQuestionResourceInfo.QuestionResUrl = WebUtils.WebRoot + "/QeustionResource/" + newFileName;
            objQuestionResourceInfo.QuestionResUploadFileName = newFileName;
            objQuestionResourceInfo.QuestionResCreateID = int.Parse(ViewState["UserID"].ToString());
            objQuestionResourceInfo.QuestionResCreateTime = DateTime.Now;
            objQuestionResourceInfo.QuestionResUpdateTime = DateTime.Now;

            if (objQuestion.CreateQuestionResource(objQuestionResourceInfo))
            {
                Script.ShowAndRedirect(this, "操作成功", "QuestionResourceList.aspx");
            }
            else
            {
                Script.ShowAndRedirect(this, "操作失败", "QuestionResourceList.aspx");
            }
        }
        catch (Exception ex)
        {
            Script.Alert(ex.Message);
        }

    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Script.RedirectURL("QuestionResourceList.aspx");
    }
}
